/*
 *  VideoController.cpp
 *  scoreBoard
 *
 *  Created by Wouter on 20-07-11.
 *  Copyright 2011 W. Reckman. All rights reserved.
 *
 */
#include "Settings.h"
#include "ScoreBoardApp.h"
#include "VideoController.h"

VideoController::VideoController( const ScoreBoardApp& appRef_ )
: s( Settings::getInstance() ), appRef( appRef_ ), video( 0 )
{}

VideoController::~VideoController() {
	delete video;
}

void VideoController::setup() {
	bool videoEnabled = parseBool( *s.getValue( "video_enabled", "true" ) );
	videoHasMirror = parseBool( *s.getValue( "video_has_mirror", "true" ) );
	videoBalanceWindow = ofToFloat( *s.getValue( "video_balance_window", "true" ) );
	string videoFileName = *s.getValue( "background_video_file", "" );
	
	if ( videoEnabled ) {
		video = new ofxAlphaVideoPlayer();
		bool result = video->loadMovie( videoFileName );
		if ( result ) {
			video->setLoopState( OF_LOOP_NORMAL );
			video->play();
		} else {
			delete video; video = 0;
			ofLog( OF_LOG_ERROR, "(VideoController.cpp) could not load video '%s'", videoFileName.c_str() );
		}
	} else {
		ofLog( OF_LOG_WARNING, "(VideoController.cpp) video disabled" );
	}
}

void VideoController::update( float balance_ ) {
	if ( video ) {
		video->idleMovie();
	}
}

void VideoController::draw() const {
	ofSetColor( 0, 0, 0 );
	ofRect( 0, 0, appRef.getCanvasWidth(), appRef.getCanvasHeight() );
	ofSetColor( 255, 255, 255 );
	
	if ( video ) {
		video->draw( 0, 0 );
	}
}
